package com.yunkazaixian.syntelecom.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yunkazaixian.syntelecom.entity.HttpResponse;
import com.yunkazaixian.syntelecom.entity.McSimDx;
import com.yunkazaixian.syntelecom.mapper.McSimDxMapper;
import com.yunkazaixian.syntelecom.service.DXService;
import com.yunkazaixian.syntelecom.service.IMcSimFlowService;
import com.yunkazaixian.syntelecom.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.NoSuchElementException;

/**
 * 流量统计Service业务层处理
 *
 * @author Lin
 * @date 2024-05-22
 */

@Service
public class McSimFlowServiceImpl implements IMcSimFlowService {


    @Autowired
    DXService dxService;

    @Autowired
    McSimDxMapper simDxMapper;


    @Override
    public Double monthFlow(String iccid, String month) {
        // 查询数据，并检查是否为空
        McSimDx one = simDxMapper.selectOne(new LambdaQueryWrapper<McSimDx>().eq(McSimDx::getIccid, iccid));
        Double monthFlow = 0.0;
        try {
            if (one != null) {
                if (month != null && !month.isEmpty()) {
                    monthFlow = dxService.queryPakage(one.getIccid(), month + "01");
                    System.out.println(monthFlow);
                } else {
                    throw new IllegalArgumentException("Invalid month format: " + month);
                }
            } else {
                throw new NoSuchElementException("ICCID错误: " + iccid);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return monthFlow;
    }
}
